#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int compare ( const void* a, const void* b ) {
    return *(int*)a - *(int*)b;
}

int min ( int a, int b ) {
    return ( a > b ? b : a );
}

int GetLeftLength ( int n ) {
    int down1, down2, h;
    h = log(n)/log(2); 
    down1 = n- (pow(2,h)-1); /* 2^h - 1 */
    down2 = pow(2,h-1);
    return (pow(2,h-1)-1+min(down1,down2));
}

void CBST ( int* arr, int* tree, int aleft, int aright, int troot ) {
    int n = aright - aleft + 1;
    if ( n == 0 ) return;
    int L = GetLeftLength(n);
    tree[troot] = arr[aleft+L];
    int LeftTRoot = troot * 2 + 1;
    int RightTRoot = LeftTRoot + 1;
    CBST(arr, tree, aleft, aleft+L-1, LeftTRoot);
    CBST(arr, tree, aleft+L+1, aright, RightTRoot);
}

int main () {
    int i, N, X;
    int* arr, *tree;
    scanf("%d",&N);
    arr = (int*)malloc(sizeof(int)*N);
    memset(arr,0,N);    
    tree = (int*)malloc(sizeof(int)*N);
    memset(tree,0,N);
    for ( i = 0; i < N; i++ ) {
        scanf("%d", &arr[i]);
    }
    qsort(arr,N,sizeof(int),compare);
    CBST(arr, tree, 0, N-1, 0);
    printf("%d", tree[0]);
    for ( i = 1; i < N; i++ ) printf(" %d", tree[i]);
    printf("\n");
    return 0;
}